package p.ithorns.integration.aop.introduction;

import org.aopalliance.aop.Advice;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.IntroductionAdvisor;
import org.springframework.stereotype.Component;

/**
 * DogIntroductionAdvisor
 * 引介增强 IntroductionAdvisor: 当一个类需要具备另一个类的能力的时候，可以使用 IntroductionAdvisor。
 *
 * @author Ht.L
 * @date 2024-03-10 14:40
 * @since 1.0.0
 */
@Component
public class DogIntroductionAdvisor implements IntroductionAdvisor {

    @Override
    public ClassFilter getClassFilter() {
        return new ClassFilter() {
            @Override
            public boolean matches(Class<?> clazz) {
                return Dog.class.isAssignableFrom(clazz);
            }
        };
    }

    @Override
    public void validateInterfaces() throws IllegalArgumentException {

    }

    @Override
    public Advice getAdvice() {
        return new AnimalIntroductionInterceptor();
    }

    @Override
    public boolean isPerInstance() {
        return true;
    }

    @Override
    public Class<?>[] getInterfaces() {
        return new Class[]{Animal.class};
    }
}